package com.zjj.learn.designmodel.work.state;

public class MyElevator implements Elevator{

    private ElevatorStatus state;

    @Override
    public void setState(ElevatorStatus state) {
        this.state = state;
    }

    @Override
    public void open() {
        switch (this.state){
            case STOP:
                System.out.println("电梯要开门了");
                this.setState(ElevatorStatus.OPENING);
                break;
            case CLOSING:
                System.out.println("电梯要开门了");
                this.setState(ElevatorStatus.OPENING);
                break;
            case RUNNING:
                //什么事都不做
                break;
            case OPENING:
                System.out.println("电梯要开门了");
            default:
                break;
        }
    }

    @Override
    public void close() {
        switch (this.state){
            case STOP:
                // do nothing
                break;
            case CLOSING:
                // do nothing
                break;
            case RUNNING:
                // do nothing
                break;
            case OPENING:
                System.out.println("电梯要关门了。。。");
                this.setState(ElevatorStatus.CLOSING);
                break;
            default:
                break;
        }
    }

    @Override
    public void run() {
        switch (this.state){
            case STOP:
                System.out.println("电梯要运行了。。。");
                this.setState(ElevatorStatus.RUNNING);
                break;
            case CLOSING:
                System.out.println("电梯要运行了。。。");
                this.setState(ElevatorStatus.RUNNING);
                break;
            case RUNNING:
                // do nothing
                break;
            case OPENING:
                // do nothing
                break;
            default:
                break;
        }
    }

    @Override
    public void stop() {
        switch (this.state){
            case STOP:
                break;
            case CLOSING:
                System.out.println("电梯要停止了。。。");
                this.setState(ElevatorStatus.STOP);
                break;
            case RUNNING:
                System.out.println("电梯要停止了。。。");
                this.setState(ElevatorStatus.STOP);
                break;
            case OPENING:
                break;
            default:
                break;
        }
    }
}
